package 栈和队列;

import java.util.Stack;

public class LC_232用栈实现队列 {
    public static void main(String[] args){
        LC_232用栈实现队列 obj=new LC_232用栈实现队列();

    }

    private Stack<Integer> A;
    private Stack<Integer> B;
    public LC_232用栈实现队列() {
        A=new Stack<>();
        B=new Stack<>();
    }

    public void push(int x) {
        A.push(x);
    }

    public int pop() {
        int peek=peek();
        B.pop();
        return peek;

    }

    public  int peek() {
        if(!B.empty()) return B.peek();
        if(A.empty()) return -1;
        while(!A.empty()){
            B.push(A.pop())
;        }
        return B.peek();
    }

    public boolean empty() {
        return A.isEmpty() && B.isEmpty();
    }
}
